package com.dodoke.cake.controller;

import com.dodoke.cake.bean.User;
import com.dodoke.cake.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class loginController {
    @Autowired
    private LoginService loginService;


    @RequestMapping("/login")
    public String login(){
        return "login";
    }
    @RequestMapping("/toLogin")
    public String login(User user, Model model) {
        System.out.println(user.getUsername());
        user = loginService.login(user.getUsername());
        if(user != null){
            //model.addAttribute("user",user);
            return "cake_list";
        }
        return "login";
    }

}
